# -*- encoding:utf-8 -*-

import os

print('***获取当前目录***')
print(os.getcwd())
print(os.path.abspath(os.path.dirname(__file__)))

print('***获取上级目录***')
print(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
print(os.path.abspath(os.path.dirname(os.getcwd())))
print(os.path.abspath(os.path.join(os.getcwd(), "..")))

print('***获取上上级目录***')
print(os.path.abspath(os.path.join(os.getcwd(), "../..")))

print('***得到当前文件夹下的所有文件和文件夹***')
print(os.listdir(os.getcwd()))

print('***删除文件***')
tmp_file_path = "tmp.txt"
tmp_file = open(tmp_file_path, 'w')
tmp_file.close()
os.remove(tmp_file_path)
print(os.listdir(os.getcwd()))

print("***检查是否是文件／文件夹***")
file_path = os.getcwd() + os.sep + "test.txt"
dir_path = os.getcwd() + os.sep
print(os.path.isfile(file_path))
print(os.path.isdir(dir_path))

print("***检查文件路径是否存在***")
print(os.path.exists(file_path))

print("***分离文件名,分离扩展名***")
[dirname, filename] = os.path.split(file_path)
print(dirname, "\n", filename)

[fname, fename] = os.path.splitext(file_path)
print(fname, "\n", fename)

print("***获得文件路径,获得文件名,获得当前环境***")
print("get pathname:", os.path.dirname(file_path))
print("get filename:", os.path.basename(file_path))
print(os.getenv)
